#!/bin/bash

# Test IO NIC function

. ./common

trap "_uninit; exit \$status" 0 1 2 3 15

_uninit()
{
	iptables -D INPUT -p tcp --sport 8001 -j DROP
	iptables -D INPUT -p tcp --dport 8001 -j DROP
}

_need_to_be_root

for i in `seq 0 5`; do
	_start_sheep $i "-i host=127.0.0.1,port=$((8000+$i))"
done

_wait_for_sheep 6

_cluster_format -c 6

_vdi_create test 100M
dd if=/dev/zero | $DOG vdi write test &

# simulate IO NIC down of sheep 1
iptables -A INPUT -p tcp --sport 8001 -j DROP
iptables -A INPUT -p tcp --dport 8001 -j DROP

# wait for dog to finish
wait
# Logger flush in 1 second internval. We need assure log is flushed.
sleep 1

if [ "`grep fallback $STORE/0/sheep.log`" ];then
	echo fallback done
fi
$DOG vdi check test 2> /dev/null

status=0
